IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spRequests_Create')
	BEGIN
		PRINT 'Dropping Procedure spRequests_Create'
		DROP  Procedure  spRequests_Create
	END

GO

PRINT 'Creating Procedure spRequests_Create'
GO
CREATE Procedure dbo.spRequests_Create
	( 	  
	  @CreatedByUser_ID numeric(9,0) = null, 
		@RequestDate DateTime = null, 
		@RequestStatus varchar(50) = null, 
		@Comments varchar(50) = null, 
		@ApprovedByUser_ID numeric(9,0) = null, 
		@ApprovedDate DateTime = null, 
		@OpenByUser_ID numeric(9,0) = null, 
		@OpenDate DateTime = null, 
		@ClosedByUser_ID numeric(9,0) = null, 
		@ClosedDate DateTime = null, 
		@DepartmentName varchar(50) = null, 
		@DivisionName varchar(50) = null
	)
AS
  /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 2007/11/02    Initial version created
    ------------------------------------------------------------------------------
  */

	-- Declare the required variables

	-- Create the required new record
	INSERT INTO Requests
	  (
		CreatedByUser_ID,
			RequestDate,
			RequestStatus,
			Comments,
			ApprovedByUser_ID,
			ApprovedDate,
			OpenByUser_ID,
			OpenDate,
			ClosedByUser_ID,
			ClosedDate,
			DepartmentName,
			DivisionName	  
	  )
	VALUES
	  (
		@CreatedByUser_ID,
			@RequestDate,
			@RequestStatus,
			@Comments,
			@ApprovedByUser_ID,
			@ApprovedDate,
			@OpenByUser_ID,
			@OpenDate,
			@ClosedByUser_ID,
			@ClosedDate,
			@DepartmentName,
			@DivisionName
	  )

	-- Handle any errors
	IF @@ERROR != 0
	BEGIN
		RAISERROR('spRequests_Create: Unable to Insert a new Requests', 10, 1)
		RETURN
	END

	-- Return the newly created ID
	SELECT	@@IDENTITY AS 'Requests_ID'

	-- Return to calling method
	RETURN 

GO
